/*
 * ========THE SOLMIX PROJECT=====================================
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.gnu.org/licenses/ 
 * or see the FSF site: http://www.fsf.org. 
 */

package org.solmix.fmk;

import java.util.Hashtable;
import java.util.Locale;
import java.util.ResourceBundle;

import org.solmix.api.i18n.ResourceBundleManager;
import org.solmix.commons.collections.DataTypeMap;
import org.solmix.fmk.i18n.ResourceBundleManagerImpl;
import org.solmix.fmk.internel.DSConfigManager;
import org.solmix.fmk.servlet.RequestContext;
import org.solmix.fmk.util.MessageTools;

/**
 * 
 * @author solomon
 * @version $Id$ 2011-3-16
 */

@SuppressWarnings("unchecked")
public final class VirtualContext extends Hashtable
{

    /**
    * 
    */
    private static final long serialVersionUID = -4923063229643617796L;

    private MessageTools msgTool;

    private static DataTypeMap globalConfig;

    private String language;


    public MessageTools getMsgTool() {
        if (msgTool == null) {
            ResourceBundleManager rbm = new ResourceBundleManagerImpl();

            ResourceBundle bundle = rbm.getResourceBundle(new Locale(getLanguage()));
            msgTool = new MessageTools(bundle, this);
        }
        return msgTool;
    }

    public void setMsgTool(MessageTools msgTool) {
        this.msgTool = msgTool;
    }

    public String getLanguage() {
        if (language == null)
            language = DSConfigManager.getConfig().getString("virtual.language", Locale.ENGLISH.getLanguage());
        return language;
    }

    public void setLanguage(String language) {
        this.language = language;
    }

    private final String name;

    VirtualContext(String name, RequestContext context)
    {
        this.name = name;
    }

}
